/**
 * related to followDetailInfo.ui
 * 
 * @Author : ln007
 * @Timestamp : 2017-04-29
 */
var nf = sm("do_Notification");
var app = sm("do_App");
var page = sm("do_Page");
var Controller = require("core/controller");
var log = require("util/log")
var navigate = require("util/navigate")
var router = require("config/router")
var net = require("util/net");
var server = require('config/server')
var fi_grid=ui('fi_grid')
var filter = require('util/filter')

Controller({
	config : {
		name : '跟进详情',
		header : {
			title : '跟进详情'
		}
	},
	name : 'index',
	mapping : {
		"fi_relation.text":"flowlist.follTarget",
		"fi_userName.text":"flowlist.follCust",
		"fi_wishInfo.text":"flowlist.follFeedback",
		"fi_address.text":"flowlist.follPhoneNum",
		"fi_updateDate.text":"flowlist.follTime",
		"fi_outUserName.text":"flowlist.follName",
		"fi_teamCui.text":"flowlist.deptName",
		"fi_followCont.text":"flowlist.follContent",
		"fi_targetRight.fontColor":"flowlist.fi_targetLable",
		"fi_targetLeft.fontColor":"flowlist.fi_targetLable",
		"fi_relation.fontColor":"flowlist.fi_targetLable",
		//fi_grid   grid
			"fi_grid":"gridList"
	},
	data : {
		flowlist:{
			follTarget:"",
			follCust:"",
			follFeedback:"",
			follPhoneNum:"",
			follTime:"",
			follName:"",
			deptName:"",
			follContent:"",
			fi_targetLable:""
		},
		gridList : [{
			"url":"",
			"realName":"",
			"size":""
		}
		]
		,newFollw:[]
	},
	event : {
//		'btn_addRecord':{
//			'touch':function(){
//				this.openAddRecord(this.data.data2)
//			}
//		},
//		'cf_lv' : {
//		'touch' : function(index) {
////			获取点击list的数据并发送到下一级页面
//			this.toFollowInfo('cf_lv', this.data.data2[index]);
//		}
//	},
	},
	methods : {
//		getFlowIcon: function (flowicon) {
////			log.info(12345,flowicon.fileIds,999999)	
//			net.send({
//				server:server.organization.followDetailIcon,
//				data:{
//					
//				},
//				success:function(iconlist){	
//					
//				},
//				error : function(data) {
//					log.info(5121451,data)
//				},
//				scope:this
//			})
//		},
		getFlowFileID: function (flowfiel) {
			net.send({
				server:server.organization.getFollowIconId,
				data:{
					follId:	flowfiel.follId
				},
				success:function(iconid){	
					log.info(656544,iconid)
					this.data.gridList=iconid.map(function(x) {
						return {
							url:x.url,
							realName:x.realName,
							size:Math.round(x.size/1024)+".KB",
							fi_fileImg:x.url
						}
					})
					this.refresh('fi_grid')
				},
				error : function(data) {
					log.info(5121451,data)
				},
				scope:this
			})
		},
		getFlowInfo: function (flowitem) {
			log.info(88888888888,flowitem,999999)
			var flowAddress=filter.getCityName(flowitem.follProvid)+filter.getCityName(flowitem.follCityid)+filter.getCityName(flowitem.follAreaid)+flowitem.follPhoneNum
			this.data.newFollw.push({
				follTarget:flowitem.follTarget,
				follCust:flowitem.follCust,
				follFeedback:flowitem.follFeedback,
				follPhoneNum:flowAddress,
				follTime:flowitem.follTime,
				follName:flowitem.follName,
				deptName:flowitem.deptName,
				follContent:flowitem.follContent})
				var list=this.data.newFollw.map(function(x) {
					var targetType=x.follTarget===145?"#28313EFF":"#A9A9A9FF"
					return {
						follTarget : filter.typeCodeConvert(x.follTarget)||'',
						follCust : filter.typeCodeConvert(x.follCust)||'',
						follFeedback : filter.typeCodeConvert(x.follFeedback)||'',
						follPhoneNum : filter.typeCodeConvert(x.follPhoneNum)||'',
						follTime : filter.typeCodeConvert(x.follTime)||'',
						follName : filter.typeCodeConvert(x.follName)||'',
						follContent : filter.typeCodeConvert(x.follContent)||'',
						deptName:filter.typeCodeConvert(x.deptName)||'',
						fi_targetLable:targetType
					}
				})
			this.data.flowlist=list[0]
			this.refresh('$')
		},
	},
	loaded : function(data) {
		this.data.dataFollowDetail=data
		this.getFlowInfo(this.data.dataFollowDetail.current)
		this.getFlowFileID(this.data.dataFollowDetail.current)
		
	}
})